package com.gitee.chippyer.logger.repository;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.gitee.chippyer.logger.compontents.LogRepositoryCommonComponent;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 日志存储仓库MYSQL自动配置类
 *
 * @author: chippy
 */
@Configuration
@MapperScan({"com.gitee.chippyer.logger.repository.ability"})
public class LogStoreRepositoryMysqlContextAutoConfiguration {

    @Bean
    public LogRepositoryCommonComponent logRepositoryCommonComponent() {
        return new LogRepositoryCommonComponent();
    }

    @Bean
    public LogStoreRepository mysqlLogStoreRepository(LogRepositoryCommonComponent logRepositoryCommonComponent) {
        return new MysqlLogStoreRepositoryImpl(logRepositoryCommonComponent);
    }

    @Bean
    public TraceStoreRepository mysqlTraceStoreRepositoryImpl() {
        return new MysqlTraceStoreRepositoryImpl();
    }

    @ConditionalOnMissingBean
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        final MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }

}
